<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <title>数据字典新增</title>
</head>
<jsp:include page="/common/meta.jsp"></jsp:include>
<jsp:include page="/common/resource.jsp"></jsp:include>
<script type="text/javascript">
/** 关闭窗口*/
function dialogClose() {
	//关闭自己
	if ($.easyui.showDialog.parent.doSearch) {
		$.easyui.showDialog.parent.doSearch();
	} else {
		$.easyui.showDialog.parent.location.reload();
		//刷新父页面
	}
	$.easyui.showDialog.parent.easyuiDialog.close();
}

function doSave() {
    /**验证数据**/
    if( !ValidateForm("#DictionaryShop_add_form")){
        return ;
    }
    /**验证数据**/
    var customerReg = new RegExp(/^\w*$/);
    var tab_nameVal = $('#tab_name').val();
    var column_nameVal = $('#column_name').val();
    if (tab_nameVal == '' || !customerReg.test($('#tab_name').val())) {
        top.$.messager.alert('提示', "表名不能包含【#】号", 'info');
        return;
    } else if (column_nameVal == ''
        || !customerReg.test($('#column_name').val())) {
        top.$.messager.alert('提示', "列名不能包含【#】号", 'info');
        return;
    }
    $.ajax({
        url : "${base}/system/dictionaryshop/DictionaryShopController/save",
        data : $("#dictionary_add_form").serialize(),
        type : "POST",
        dataType : "JSON",
        cache : false,
        beforeSend : function(xhr) {
            $ .blockUI({ message : '<img src=\"${base}/image/login/large-loading.gif\" alt=\"正在处理...\">' 	});
        },
        complete : function(xhr, ts) {
            $.unblockUI();
        },
        success : function(data) {
            var flag = data.flag;
            if (flag) {//验证成功
                top.$.messager.alert('提示', "保存成功", 'info', function() {
                    dialogClose();
                });
            } else {//验证失败
                var type = data.type;
                var msg = data.msg;
                top.$.messager.alert('保存失败', msg, 'info');
            }
        }
    });
}

var newDiv = "<div class=\"fitem\" style=\"width:1290px\" >"
    + "<div class=\"form-group notnull\">"
    + "<div class=\"form-label w36\">列说明</div>"
    + "<div class=\"form-editor w64\">"
    + "<input  type=\"text\" id=\"column_content\" name=\"sysconfigList.column_content\" class=\"easyui-textbox\"	data-options=\"required:true,novalidate:true,missingMessage:'列说明不允许为空'\"  ></input>"
    + "</div></div>"
    + "<div class=\"form-group notnull\">"
    + "<div class=\"form-label w36\">列值</div>"
    + "<div class=\"form-editor w64\">"
    + "<input   type=\"text\" id=\"column_value\" name=\"sysconfigList.column_value\" class=\"easyui-textbox\"	data-options=\"required:true,novalidate:true,missingMessage:'列值不允许为空'\"></input>"
    + "</div></div>"
    + "<div class=\"form-group notnull\">"
    + "<div class=\"form-label w36\">数值</div>"
    + "<div class=\"form-editor w64\">"
    + "<input   type=\"text\" id=\"column_num_value\" name=\"sysconfigList.column_num_value\" class=\"easyui-numberbox\"	data-options=\"required:true,novalidate:true,missingMessage:'数值不允许为空'\"></input>"
    + "</div></div>"
    + "<div class=\"form-group\">"
    + "<div class=\"form-label w36\">序号</div>"
    + "<div class=\"form-editor w64\">"
    + "<input   type=\"text\" id=\"column_order\" name=\"sysconfigList.column_order\" class=\"easyui-textbox\"></input>"
    + "</div></div>"
    + "<div>"
    + "<a href=\"javascript:void(0)\" class=\"easyui-linkbutton\" iconCls=\"icon-add\" plain=\"false\" onclick=\"addItem()\" style=\"height: 32px; margin:2px;\">增加</a>"
    + "<a href=\"javascript:void(0)\" class=\"easyui-linkbutton\" iconCls=\"icon-remove\" plain=\"false\" onclick=\"removeItem(this)\" style=\"height: 32px; margin:2px;\" >删除</a>"
    + "</div>" + "</div>";

function addItem(tempStr) {
    debugger;
    var tempVal = $("#itemsCount").val();
    if (tempVal == "") {
        tempVal = 1;
    }
    var count;
    if (tempVal >= 1) {
        count = tempVal - 1;
    }
    var tempHtml = $(newDiv);
    tempHtml.find("input").each(function() {
        var name = $(this).attr("name");
        if (null != name) {
            name = name.split(".")
            var nameStr = name[0] + "[" + count + "]." + name[1];
            $(this).attr("name", nameStr);
        }
    });
    $.parser.parse(tempHtml);
    $("#items").append(tempHtml);
    $("#itemsCount").val(++tempVal);
}
/**
 * 删除一行
 */
function removeItem(tempStr) {
    var tempVal = $("#itemsCount").val();
    if ("" == tempVal || 1 == tempVal) {
        return;
    } else {
        $('#items').find('div.fitem:last-child').remove();
        $("#itemsCount").val(--tempVal);
    }

}
</script>
<body>
<div id="DictionaryShop_add_div" class="form-box" style="padding-top:10px;height: 85% ">
    <!-- form-box begin -->
    <div id="DictionaryShop_add_form" class="form-box" style="padding-top:10px; ">
        <form id="dictionary_add_form">
            <div class="form-group notnull">
                <div class="form-label w36">表名</div>
                <div class="form-editor w64">
                    <input type="text" id="tab_name"  name="tab_name" class="easyui-textbox" data-options="required:true,novalidate:true,missingMessage:'表名不允许为空'"  />
                </div>
            </div>

            <div class="form-group notnull">
                <div class="form-label w36">列名</div>
                <div class="form-editor w64">
                    <input type="text" id="column_name"  name="column_name" class="easyui-textbox" data-options="required:true,novalidate:true,missingMessage:'列名不允许为空'"  />
                </div>
            </div>
            <div style="clear: both"></div>
            <input type='hidden' id='itemsCount' value='1' />
            <div id="items"  >
                <div   id="config"  >
                    <jsp:include page="vo/addVO.jsp"></jsp:include>
                    <a href="javascript:void(0)" class="easyui-linkbutton" plain = "false"  iconCls="icon-add" onclick="addItem()" plain="true" style="height: 32px;margin-bottom: 6px;margin-left: 2px;">增加</a>
                    <a href="javascript:void(0)" class="easyui-linkbutton" plain = "false"  iconCls="icon-remove" onclick="removeItem(this)" plain="true" style="height: 32px;margin-bottom: 6px;margin-left: 1px;">删除</a>
                 </div>
            </div>
            <div class="form-group-two " style="height: 60px;">
                <div class="form-label w36   ">备注</div>
                <div class="form-editor w64">
                    <input class="easyui-textbox" id ="memo" name="memo" data-options="multiline:true "  style="width:450px;height:50px">
                </div>
            </div>
        </form>
    </div>
    <!-- form-box end -->
</div>
<div id="childButtons" style=" margin-right: 10px;text-align: right;">
    <a href="javascript:void(0)" class="easyui-linkbutton button-blue l-btn l-btn-small" id="save" onclick="doSave()">保存</a>
    <a href="javascript:void(0)" class="easyui-linkbutton button-red l-btn l-btn-small"  id="close" onclick="dialogClose()">关闭</a>
</div>
</body>
</html>
<script type="text/javascript">
    $(function(){
        $.fn.form.methods.enableAutoFocus($("#DictionaryShop_add_form"));
    });
</script>